package String;

import org.junit.jupiter.api.Test;
import reflex.en.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class StringUtil {

    /**
     * 正则表达式
     */
    @Test
    public void test(){
        String id = "522601196701123001";
        String ids = "[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)";

        System.out.println(id.matches(ids));

    }
    @Test
    void test1(){
        Pattern p = Pattern.compile("/*DELETE,*");
        Matcher m = p.matcher("DELET");
        boolean b = m.matches();
        System.out.println(b);
    }
    @Test
    void test2(){
        StringBuffer dd = new StringBuffer() ;
        dd.append("cccaaa,");
        dd.replace(dd.length()-1,dd.length(),"。");
        System.out.println(dd.toString());
    }
    @Test
    void test3(){
        String cc = "cccaaa,";
        String   dd =  cc.substring(cc.length()-1);
        System.out.println(dd);
    }

  @Test
    void test4(){
        List<User> list = addList();
      long star = System.currentTimeMillis();
      Map<String, User> entityMap= list.stream().collect(Collectors.toMap(User::getName, Function.identity(), (entity1, entity2) -> entity1));
      System.out.println(System.currentTimeMillis() - star);

      long star2 = System.currentTimeMillis();
      Map<String, User> entityMap1 = new HashMap<>();
      for (User user : list) {
          entityMap1.put(user.getName(),user);
      }
      System.out.println(System.currentTimeMillis() - star2);

    }
    @Test
     public void Testinstanceof(){
//        String cc = "ccccc";
        final String cc ;
        cc="444cacac";
        System.out.println(cc.indexOf("c"));

//        cc="333";
        System.out.println(cc);



    }

     static  {
        System.out.println("你是撒");
    }
//    @Test

    void testhashCode(){
        int a;
        System.out.println("1".hashCode());
    }

    List<User> addList(){
        List<User> list = new ArrayList<>();
        list.add(new User("111",222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User("1114",222,"ddd"));
        list.add(new User("1114",2223,"ddd"));   list.add(new User("111",222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User("1114",222,"ddd"));
        list.add(new User("1114",2223,"ddd"));   list.add(new User("111",222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User("1114",222,"ddd"));
        list.add(new User("1114",2223,"ddd"));   list.add(new User("111",222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User("1114",222,"ddd"));
        list.add(new User("1114",2223,"ddd"));   list.add(new User("111",222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User(null,222,"ddd"));
        list.add(new User("1114",222,"ddd"));
        list.add(new User("1114",2223,"ddd"));
        for (int i = 0; i < 4000; i++) {
            list.add(new User("1114",2223,"ddd"));
        }
        return list;
    }


}

abstract class Cat {
    public void Cat(){

    }
    public  void sayHi() {
        System.out.println("hi~");
    }
}
